package Testing;

import DeportManage.CustomerList;
import DeportManage.Customer;
import DeportManage.DuplicateException;
import DeportManage.ErrorFormatNameException;
import DeportManage.Name;
import DeportManage.NotFormatParcelIDException;
import DeportManage.NotFoundCustomerByNoException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class CustomerListTest {
	
	CustomerList customerlist;

	/**
	 * Initializing the Customers in the CustomerList
	 *  Example one is name: Madiha Jami, ID:C5888 as Customer 0
	 *  Example one is name: John Gothamburg, ID:X7788 as Customer 1
	 *  Example one is name: Joe Black, ID:C1234 as Customer 2
	 *  Example one is name: Huiyu Tao, ID:C7867 as Customer 3
	 */
	@Before
	public void setup() throws DuplicateException, NotFormatParcelIDException, ErrorFormatNameException
	{
		customerlist = new CustomerList();
		int sequenceNo = 1;
		Name name = new Name("Madiha Jami");
		String id_parcel = "C5888";
		Customer customer0 = new Customer(sequenceNo,name,id_parcel);
		
		sequenceNo = 2;
		name = new Name("John Gothamburg");
		id_parcel = "X7788";
		Customer customer1 = new Customer(sequenceNo,name,id_parcel);
		
		sequenceNo = 3;
		name = new Name("Joe Black");
		id_parcel = "C1234";
		Customer customer2 = new Customer(sequenceNo,name,id_parcel);
		
		sequenceNo = 8;
		name = new Name("Huiyu Tao");
		id_parcel = "C7867";
		
		Customer customer3 = new Customer(sequenceNo,name,id_parcel);
		customerlist.addCustomer(customer0);
		customerlist.addCustomer(customer1);		
		customerlist.addCustomer(customer2);		
		customerlist.addCustomer(customer3);
	}
	
	@After
	public void tearDown() {
		customerlist = new CustomerList();
	}
	
	/**
	 * Test method to check the customers added in the CustomerList
	 * Example taken is Yancho Yu with the ID X9878
	 * Example taken is Yewr Yao with the ID C1234
	 */
	@Test(expected = DuplicateException.class)
	public void testaddCustomer() throws NotFoundCustomerByNoException,
	DuplicateException, NotFormatParcelIDException, ErrorFormatNameException{
		// Search for Customer whose sequence number is 8
		customerlist.addCustomer(new Customer(9,new Name("Yanchao Yu"), "X9878"));
		// Search for Customer whose sequence number is 118;
		customerlist.addCustomer(new Customer(9,new Name("Yewr Yao"), "C1234"));
	}
	
	/**
	 * Test method to check the Size of the Customer list
	 * getSize () method has been used to get the size of the Customer List
	 */
	@Test
	public void testgetsize() throws DuplicateException, NotFormatParcelIDException, ErrorFormatNameException{
		int expected_size = 4;
		String message_a = "Failed for size of customer list: 4";
		int actuall_size = customerlist.getSize();
		assertEquals(message_a, expected_size, actuall_size);	
	}
	
	/**
	 * Test method to check the Customer by Sequence Number
	 * Example taken Sequence no. 8 and 118
	 */
	@Test(expected = NotFoundCustomerByNoException.class)
	public void testsearchCustomerBySequenceNo() throws NotFoundCustomerByNoException{
		// Search for Customer whose sequence number is 8
		Customer customer0 = customerlist.searchCustomerBySequenceNo(8);
		// Search for Customer whose sequence number is 118
		Customer customer1 = customerlist.searchCustomerBySequenceNo(118);
	}
	
	/**
	 * Test method to check whether the sequence no is found or not
	 * Example taken Sequnce no. 8,188;
	 */
	@Test
	public void testBoolFindbySeqenceNo(){
		// Example 8, which is found 
		assertTrue(customerlist.isExistSeqNo(8));
		
		// Example 118, which is not found
		try{
		assertTrue(customerlist.isExistSeqNo(188));
		}
		catch(AssertionError ae){System.out.print("the Seq No is not found: 118");}
		
	}
}